package com.example.demo.dto;

import java.time.LocalDateTime;

public class DataSourceDTO {
    private Long id;                        // 主键ID
    private String name;                    // 数据源名称
    private String dbType;                  // 数据库类型
    private String host;                    // 主机地址
    private Integer port;                   // 端口号
    private String username;                // 用户名
    private String passwordEncrypted;       // 加密后的密码
    private String databaseName;            // 数据库名称
    private String querySql;                // 查询SQL
    private String idFields;                // ID字段配置，JSON格式
    private String displayFields;           // 展示字段配置，JSON格式
    private String extraFields;             // 额外字段配置，JSON格式
    private String dropdownFields;          // 下拉字段配置，JSON格式
    private String searchableFields;        // 搜索字段配置，JSON格式
    private Integer status;                 // 状态：1=启用，0=禁用
    private Integer scheduleEnabled;        // 是否启用定时任务，1=启用，0=禁用
    private String scheduleCron;            // 定时任务Cron表达式
    private String scheduleDesc;            // 定时任务描述
    private LocalDateTime createdAt;        // 创建时间
    private LocalDateTime updatedAt;        // 更新时间

    // 从实体类转换为DTO
    public static DataSourceDTO fromEntity(com.example.demo.entity.DataSource entity) {
        DataSourceDTO dto = new DataSourceDTO();
        dto.setId(entity.getId());
        dto.setName(entity.getName());
        dto.setDbType(entity.getDbType());
        dto.setHost(entity.getHost());
        dto.setPort(entity.getPort());
        dto.setUsername(entity.getUsername());
        dto.setPasswordEncrypted(entity.getPasswordEncrypted());
        dto.setDatabaseName(entity.getDatabaseName());
        dto.setQuerySql(entity.getQuerySql());
        dto.setIdFields(entity.getIdFields());
        dto.setDisplayFields(entity.getDisplayFields());
        dto.setExtraFields(entity.getExtraFields());
        dto.setDropdownFields(entity.getDropdownFields());
        dto.setSearchableFields(entity.getSearchableFields());
        dto.setStatus(entity.getStatus());
        dto.setScheduleEnabled(entity.getScheduleEnabled());
        dto.setScheduleCron(entity.getScheduleCron());
        dto.setScheduleDesc(entity.getScheduleDesc());
        dto.setCreatedAt(entity.getCreatedAt());
        dto.setUpdatedAt(entity.getUpdatedAt());
        return dto;
    }

    // 从DTO转换为实体类
    public com.example.demo.entity.DataSource toEntity() {
        com.example.demo.entity.DataSource entity = new com.example.demo.entity.DataSource();
        entity.setId(this.getId());
        entity.setName(this.getName());
        entity.setDbType(this.getDbType());
        entity.setHost(this.getHost());
        entity.setPort(this.getPort());
        entity.setUsername(this.getUsername());
        entity.setPasswordEncrypted(this.getPasswordEncrypted());
        entity.setDatabaseName(this.getDatabaseName());
        entity.setQuerySql(this.getQuerySql());
        entity.setIdFields(this.getIdFields());
        entity.setDisplayFields(this.getDisplayFields());
        entity.setExtraFields(this.getExtraFields());
        entity.setDropdownFields(this.getDropdownFields());
        entity.setSearchableFields(this.getSearchableFields());
        entity.setStatus(this.getStatus());
        entity.setScheduleEnabled(this.getScheduleEnabled());
        entity.setScheduleCron(this.getScheduleCron());
        entity.setScheduleDesc(this.getScheduleDesc());
        entity.setCreatedAt(this.getCreatedAt());
        entity.setUpdatedAt(this.getUpdatedAt());
        return entity;
    }
    
    // Getters and Setters
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getDbType() {
        return dbType;
    }
    
    public void setDbType(String dbType) {
        this.dbType = dbType;
    }
    
    public String getHost() {
        return host;
    }
    
    public void setHost(String host) {
        this.host = host;
    }
    
    public Integer getPort() {
        return port;
    }
    
    public void setPort(Integer port) {
        this.port = port;
    }
    
    public String getUsername() {
        return username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    public String getPasswordEncrypted() {
        return passwordEncrypted;
    }
    
    public void setPasswordEncrypted(String passwordEncrypted) {
        this.passwordEncrypted = passwordEncrypted;
    }
    
    public String getDatabaseName() {
        return databaseName;
    }
    
    public void setDatabaseName(String databaseName) {
        this.databaseName = databaseName;
    }
    
    public String getQuerySql() {
        return querySql;
    }
    
    public void setQuerySql(String querySql) {
        this.querySql = querySql;
    }
    
    public String getIdFields() {
        return idFields;
    }
    
    public void setIdFields(String idFields) {
        this.idFields = idFields;
    }
    
    public String getDisplayFields() {
        return displayFields;
    }
    
    public void setDisplayFields(String displayFields) {
        this.displayFields = displayFields;
    }
    
    public String getExtraFields() {
        return extraFields;
    }
    
    public void setExtraFields(String extraFields) {
        this.extraFields = extraFields;
    }
    
    public String getDropdownFields() {
        return dropdownFields;
    }
    
    public void setDropdownFields(String dropdownFields) {
        this.dropdownFields = dropdownFields;
    }
    
    public String getSearchableFields() {
        return searchableFields;
    }
    
    public void setSearchableFields(String searchableFields) {
        this.searchableFields = searchableFields;
    }
    
    public Integer getStatus() {
        return status;
    }
    
    public void setStatus(Integer status) {
        this.status = status;
    }
    
    public Integer getScheduleEnabled() {
        return scheduleEnabled;
    }
    
    public void setScheduleEnabled(Integer scheduleEnabled) {
        this.scheduleEnabled = scheduleEnabled;
    }
    
    public String getScheduleCron() {
        return scheduleCron;
    }
    
    public void setScheduleCron(String scheduleCron) {
        this.scheduleCron = scheduleCron;
    }
    
    public String getScheduleDesc() {
        return scheduleDesc;
    }
    
    public void setScheduleDesc(String scheduleDesc) {
        this.scheduleDesc = scheduleDesc;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }
    
    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }
}